package cc.bookcloud.tool.ocr.common.excel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
public class Demo {
    public static void main(String[] args) {

        String fileName = "F:\\my-workspace\\lowcode-research\\Java\\work-202205\\release-assist-tool\\src\\main\\resources\\test.xls";
        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        // 这里每次会读取3000条数据 然后返回过来 直接调用使用数据就行
//        EasyExcel.read(fileName, DemoData.class, new PageReadListener<DemoData>(dataList -> {
//            for (DemoData demoData : dataList) {
//                log.info("读取到一条数据{}", JSON.toJSONString(demoData));
//            }
//        })).sheet().headRowNumber(2).doRead();

//           EasyExcel.read(fileName, DemoData.class,
//                new EasyExcelListener()).sheet(0).headRowNumber(3).doRead();

        ExcelReader build = EasyExcel.read(fileName).build();
        List<ReadSheet> readSheets = build.excelExecutor()
                .sheetList();
        //  build.close();
        for (ReadSheet readSheet : readSheets) {
            System.out.println(readSheet.getSheetName() + "," + readSheet.getSheetNo());
            //第二部分从第3行开始读
            readSheet = EasyExcel.readSheet(readSheet.getSheetNo()).head(ColumnProperty.class).registerReadListener(new EasyExcelListener()).headRowNumber(2).build();
            build.read(readSheet);
        }

        System.out.println("======================结束 ==============");
//        TableConvertDbScriptEngine.print();

    }
}
